<template>
  <el-dialog
    title="修改批次名和备注"
    destroy-on-close
    append-to-body
    :visible.sync="show"
    width="900px"
    :before-close="cancel"
  >
    <el-form ref="formRef" :model="form" :rules="rules" size="small" label-width="100px">
      <el-form-item :label="$t('批次名称')" prop="batchName">
        <el-input v-model="form.batchName" />
      </el-form-item>
      <el-form-item :label="$t('备注')" prop="remark">
        <el-input type="textarea" :rows="4" v-model="form.remark" />
      </el-form-item>

      <el-form-item prop="remark">
        <div style="display: flex; margin-bottom: -18px">
          <div style="flex: 2; text-align: center">快递公司</div>
          <div style="flex: 3; text-align: center">网址</div>
          <div style="flex: 2; text-align: center">单号</div>
        </div>
      </el-form-item>

      <div class="form-item-row">
        <div class="form-item-row_label">头程</div>
        <div class="form-item-row_content">
          <el-form-item label-width="0" prop="remark">
            <el-input v-model="form.headPathExpress" />
          </el-form-item>
          <el-form-item label-width="0" prop="remark">
            <el-input v-model="form.headPathNet" />
          </el-form-item>
          <el-form-item label-width="0" prop="remark">
            <el-input v-model="form.headPathExpressNo" />
          </el-form-item>
        </div>
      </div>
      <div class="form-item-row">
        <div class="form-item-row_label">中程</div>
        <div class="form-item-row_content">
          <el-form-item label-width="0" prop="remark">
            <el-input v-model="form.centrePathExpress" />
          </el-form-item>
          <el-form-item label-width="0" prop="remark">
            <el-input v-model="form.centrePathNet" />
          </el-form-item>
          <el-form-item label-width="0" prop="remark">
            <el-input v-model="form.centrePathExpressNo" />
          </el-form-item>
        </div>
      </div>
      <div class="form-item-row">
        <div class="form-item-row_label">尾程</div>
        <div class="form-item-row_content">
          <el-form-item label-width="0" prop="remark">
            <el-input v-model="form.tailPathExpress" />
          </el-form-item>
          <el-form-item label-width="0" prop="remark">
            <el-input v-model="form.tailPathNet" />
          </el-form-item>
          <el-form-item label-width="0" prop="remark">
            <el-input v-model="form.tailPathExpressNo" />
          </el-form-item>
        </div>
      </div>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button @click="cancel">
        <!-- 关闭 -->
        {{ $t('关闭') }}
      </el-button>
      <el-button type="primary" @click="handleSubmit">{{ $t('确定') }}</el-button>
    </div>
  </el-dialog>
</template>

<script>
import { updateBatch } from '@/api/purchasingManage/batch'
export default {
  props: {
    /**
     * formData
     */
    formData: {
      type: Object,
      default: () => ({}),
    },

    /**
     * 控制显示隐藏
     */
    show: {
      type: Boolean,
      default: false,
    },
  },
  data() {
    return {
      form: {},
      rules: {
        batchName: [{ required: true, message: '请输入', trigger: 'blur' }],
      },
    }
  },
  computed: {},
  watch: {
    show: function (newValue) {
      if (newValue) {
        Object.keys(this.formData).forEach((key) => {
          this.$set(this.form, key, this.formData[key])
        })
      }
    },
  },
  methods: {
    handleSubmit() {
      this.$refs['formRef'].validate((valid) => {
        if (valid) {
          const data = JSON.parse(JSON.stringify(this.form))
          updateBatch(data).then((res) => {
            const { code, data, msg } = res
            if (code === 200) {
              this.$message({ type: 'success', message: msg })
              this.$emit('getList')
              this.cancel()
            }
          })
        }
      })
    },
    cancel() {
      this.$emit('update:show', false)
    },
  },
}
</script>
<style scoped lang="scss">
.form-item-row {
  display: flex;
  margin-bottom: 10px;
  &_label {
    width: 100px;
    display: flex;
    align-items: center;
    justify-content: flex-end;
    padding-right: 10px;
    font-weight: bold;
  }
  &_content {
    display: flex;
    flex: 1;
    gap: 5px;
    ::v-deep .el-form-item {
      flex: 3;
      margin-bottom: 0;
      &:nth-child(1){
        flex: 2;
      }
      &:nth-child(3){
        flex: 2;
      }
    }
  }
}
</style>
